package com.wang.service.impl;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * @Classname SpringContextUtil
 * @Description TODO
 * @Date 2024/5/24 9:15
 * @Created by pc
 */
@Service
public class SpringContextUtil implements ApplicationContextAware  {
    private static ApplicationContext context;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.context = applicationContext;
    }

    public static <T> T getBean(String name, Class<T> requiredType){
        return context.getBean(name,requiredType);
    }
}
